package com.yuan.homework.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: Train
 * @description:
 * @author: yuan_boss
 * @create: 2022-11-21 19:03
 **/

@WebListener
public class ApplicationContextListener implements ServletContextListener {
    private List<String> userList;
    //定义一个判断是否重复登录的变量,如果里面的值为1，表示重复登录，
    private List<Integer> flag;
    @Override
    public void contextInitialized(ServletContextEvent sce) {

        System.out.println("Application初始化");
        userList = new ArrayList<>();
        //为true时表示没有重复登录
        flag = new ArrayList<>(1);
        //设置第一数字为0，表示没有重复登录
        flag.add(0,0);
        sce.getServletContext().setAttribute("userList",userList);
        sce.getServletContext().setAttribute("flag",flag);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("Application销毁");
    }
}
